import { h } from 'vue';
import { AdColumn } from '@/components/AdTable';
import { expandAndToString } from '@/utils/common';
import { BasicUpload } from '@/components/Upload';
import { TableImg } from '@/components/Table';
import { List } from '@/components/Linqts';
import { isArray, isNull, isObject, isString } from '@/utils/is';
import FileUpload from '@/components/Form/src/components/FileUpload.vue';
import { debug } from 'console';
import { Get as GetIpn, GetDictNodes } from '@/views/wms/ipns/ipn.api';
import { getOutStorgeStatusSchema } from './materialoutstorage.enum';

const projectDicts = (await GetDictNodes('project'))?.Data;
const outStorgeStatus = getOutStorgeStatusSchema();
export const columns: AdColumn[] = [
  {
    title: '主键',
    dataIndex: 'Id',
    dataType: 'guid',
    width: 300,
    defaultHidden: true,
    filterable: false,
    sorter: true,
    formVisible: true,
    formEditable: false,
  },
  {
    title: '出库状态',
    dataIndex: 'Status',
    dataType: 'enum',
    width: 150,
    filterable: true,
    sorter: true,
    enumData: outStorgeStatus,
  },
  {
    title: '物料编号',
    dataIndex: 'IPNNo',
    dataType: 'string',
    width: 100,
    defaultHidden: false,
    filterable: false,
    sorter: false,
    formVisible: false,
    formEditable: false,
  },
  {
    title: '仓库',
    dataIndex: 'WareHouseName',
    dataType: 'string',
    width: 100,
    defaultHidden: false,
    filterable: false,
    sorter: false,
    formVisible: false,
    formEditable: false,
  },
  {
    title: '库区',
    dataIndex: 'WareHouseAreaName',
    dataType: 'string',
    width: 100,
    defaultHidden: false,
    filterable: false,
    sorter: false,
    formVisible: false,
    formEditable: false,
  },
  {
    title: '库位',
    dataIndex: 'WareHouseAreaPosName',
    dataType: 'string',
    width: 100,
    defaultHidden: false,
    filterable: false,
    sorter: false,
    formVisible: false,
    formEditable: false,
  },
  {
    title: '所属项目',
    dataIndex: 'Project',
    dataType: 'integer',
    width: 150,
    defaultHidden: false,
    formVisible: false,
    formEditable: false,
    required: true,
    filterable: true,
    sorter: true,
    editComponent: 'ApiSelect',
    editComponentProps: {
      api: GetDictNodes,
      params: 'project',
      resultField: 'Data',
      // use name as label
      labelField: 'CodeName',
      // use id as value
      valueField: 'CodeValue',
      immediate: true,
      optionFilterProp: 'label',
      showSearch: true,
    },
    format: (_text: string, record: Recordable, _index: number) => {
      let projectName = '';
      if (isArray(projectDicts)) {
        projectName = new List(projectDicts).FirstOrDefault((a) => a.CodeValue == _text)?.CodeName;
      }
      return projectName;
    },
  },
  {
    title: '领用数量',
    dataIndex: 'Num',
    dataType: 'number',
    width: 150,
    formVisible: true,
    formEditable: true,
    required: true,
    filterable: true,
    sorter: true,
  },
  {
    title: '领用项目',
    dataIndex: 'Project',
    dataType: 'integer',
    width: 150,
    defaultHidden: false,
    formVisible: false,
    formEditable: false,
    required: true,
    filterable: true,
    sorter: true,
    editComponent: 'ApiSelect',
    editComponentProps: {
      api: GetDictNodes,
      params: 'project',
      resultField: 'Data',
      // use name as label
      labelField: 'CodeName',
      // use id as value
      valueField: 'CodeValue',
      immediate: true,
      optionFilterProp: 'label',
      showSearch: true,
    },
    format: (_text: string, record: Recordable, _index: number) => {
      let projectName = '';
      if (isArray(projectDicts)) {
        projectName = new List(projectDicts).FirstOrDefault((a) => a.CodeValue == _text)?.CodeName;
      }
      return projectName;
    },
  },
  {
    title: '用途',
    dataIndex: 'UseTarget',
    dataType: 'string',
    width: 150,
    formVisible: true,
    formEditable: true,
    required: true,
    filterable: true,
    sorter: true,
  },
  {
    title: '备注',
    dataIndex: 'Remark',
    dataType: 'text',
    width: 150,
    formVisible: true,
    formEditable: true,
    filterable: false,
    sorter: false,
    formSchema: {
      colProps: {
        xs: 24, // <576px
        sm: 24, // ≥576px
        md: 24, // ≥768px
        lg: 24, // ≥992px
        xl: 24, // ≥1200px
        xxl: 24, // ≥1600px
      },
    },
  },
  {
    title: '创建时间',
    dataIndex: 'CreatedTime',
    dataType: 'datetime',
    width: 200,
    formVisible: true,
    formEditable: false,
    required: false,
    filterable: true,
    sorter: true,
  },
];

export interface InputDto {}

export interface OutputDto {}
